package com.gzsxy.config;

import com.gzsxy.utils.SessionUserUtil;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.Map;

/**
 * @author xiaolong
 *  获取Token增强（用户信息扩展）
 * @date 2021/11/9 19:43
 */
public class CustomTokenEnhancer implements TokenEnhancer {


    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
        if (accessToken instanceof DefaultOAuth2AccessToken){
            DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) accessToken;
            System.out.println("asdafsdfsdf");
            //查询用户信息扩展
            Map<String, Object> additionalInformation = SessionUserUtil.buildTokenAdditionalInformation(authentication);

            //添加额外的用户信息扩展
            token.setAdditionalInformation(additionalInformation);
        }
        return accessToken;
    }
}
